package se.zens.demo.wsapp.implementation;

import java.util.HashMap;
import java.util.Map;

import javax.ws.rs.core.Response;

import se.zens.demo.wsapp.configuration.WSAppConfiguration;
import se.zens.demo.wsapp.implementation.customers.AddCustomerProcessor;
import se.zens.demo.wsapp.implementation.customers.DeleteCustomerProcessor;
import se.zens.demo.wsapp.implementation.customers.GetAllCustomerProcessor;
import se.zens.demo.wsapp.implementation.customers.GetCustomerProcessor;
import se.zens.demo.wsapp.implementation.customers.UpdateCustomerProcessor;
import se.zens.demo.wsapp.interfaces.CustomerService;
import se.zens.demo.wsapp.interfaces.model.Customer;

public class CustomerServiceImpl implements CustomerService
{

	private  Map<String,Customer> customers;
	
	private WSAppConfiguration config;
	
	public CustomerServiceImpl(WSAppConfiguration config)
	{
		this();
		this.config = config;
	}
	
	public CustomerServiceImpl()
	{
		customers = new HashMap<String,Customer>();
		
	}
	
	public
	String ping( )
	{
		return "pong";
	}
	
	public
	Response getCustomer( String id)
	{
		GetCustomerProcessor processor  = new GetCustomerProcessor(config, id, customers);
		processor.process();
		return processor.getResponse();
	}

	public
	Response getAll( )
	{
		GetAllCustomerProcessor processor  = new GetAllCustomerProcessor(config, customers);
		processor.process();
		return processor.getResponse();
	}
	public
	Response updateCustomer(String id,
			String name)
	{
		UpdateCustomerProcessor processor  = new UpdateCustomerProcessor(config, id,name, customers);
		processor.process();
		return processor.getResponse();
	}


	public
	Response deleteCustomer( String id)
	{
		DeleteCustomerProcessor processor  = new DeleteCustomerProcessor(config, id, customers);
		processor.process();
		return processor.getResponse();
	}

	public
	Response addCustomer(String id,
			String name)
	{
		AddCustomerProcessor processor  = new AddCustomerProcessor(config, id,name, customers);
		processor.process();
		return processor.getResponse();
	}

}
